package xginxim

import (
	"encoding/json"

	"gitee.com/xiaoyutab/xgotool/optional/xim"
	"gitee.com/xiaoyutab/xgotool/xgin"
	"gitee.com/xiaoyutab/xgotool/xstring"
)

// 获取聊天群历史消息记录
//
//	POST	user.chat.message
func userChatMessage(uid uint, b []byte) *xgin.Response {
	type temp_struct struct {
		Id json.Number `json:"id" form:"id"`
		Pages
	}
	temp := temp_struct{}
	if err := json.Unmarshal(b, &temp); err != nil {
		return xgin.Resp().Error(err)
	}
	count, lists, err := xim.GetChatMessage(xstring.JUint64(temp.Id), temp.Offset(), temp.Limit())
	if err != nil {
		return xgin.Resp().Error(err)
	}
	return xgin.Resp().PageNoGC(temp.Page(), temp.Limit(), lists, count)
}
